# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gobject-introspection

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.40.0
pkgrel=1
pkgdesc="GObject Introspection can scan C header and source files in order to generate introspection typelib files (mingw-w64)"
arch=('any')
url="https://live.gnome.org/GObjectIntrospection"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-python2")
depends=(
    "${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-glib2"
    "${MINGW_PACKAGE_PREFIX}-cairo"
    "${MINGW_PACKAGE_PREFIX}-libffi"
    )
options=('strip' 'staticlibs')

source=(http://ftp.gnome.org/pub/GNOME/sources/gobject-introspection/${pkgver%.*}/${_realname}-${pkgver}.tar.xz
    0012-fix-runtime-prefix.mingw.patch
    0018-debug-rmtree-errors.mingw.patch
    0021-tests-no-undefined.patch
    0050-dont-load-msvcrt.patch
    0055-fix-python-detection.patch
    )

md5sums=('bbb103b5d88dbf2a257b7a26ae9bc666'
         'f164bfa9b3caa66dc664131a729b3a70'
         'f0ecde986ebf1f0e28b752f9c36fb6c1'
         '69ef34e2f57abc8afe1b9f6fa3786e97'
         'e3598d539258678eef8dde2216419faf'
         '6d809bf266e42a20b31a7acbaf0384d1')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0012-fix-runtime-prefix.mingw.patch
  patch -p1 -i ${srcdir}/0018-debug-rmtree-errors.mingw.patch
  patch -p1 -i ${srcdir}/0021-tests-no-undefined.patch
  patch -p1 -i ${srcdir}/0050-dont-load-msvcrt.patch
  patch -p1 -i ${srcdir}/0055-fix-python-detection.patch

  autoreconf -fi
}

build() {
  export PYTHON=${MINGW_PREFIX}/bin/python2
  
  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null

  CFLAGS+=" -mms-bitfields"
  CXXFLAGS+=" -mms-bitfields"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-silent-rules
  make -j1
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' -o -name '*.manifest' | xargs -rtl1 rm
  #rm -r "${pkgdir}${MINGW_PREFIX}/share/man"
}
